﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AirlineProject.Models;
namespace AirlineProject.Areas.admin.Controllers
{
    public class editController : Controller
    {
        private DataClassesProjectAirlineDataContext dc = new DataClassesProjectAirlineDataContext();

        //*******************edit flight********************************
        public  ActionResult  editflight(int  id)
        {
            Flight  get = dc.Flights.Where(ac => ac.flight_id == id).First();
            return  View(get);
        }

         [HttpPost]
        public  ActionResult  editflight(int  id, Flight  ace)
        {
            if  (ModelState.IsValid)
            {
                Flight  get = dc.Flights.Where(ac => ac.flight_id == id).First();

                get.flight_id = ace.flight_id;
                get.origin_id = ace.origin_id;
                get.destination_id = ace.destination_id;
                get.departure_date = ace.departure_date;
                get.flight_price = ace.flight_price;
                get.seat_num = ace.seat_num;
                dc.SubmitChanges();
                RedirectToAction("Flight", "templateadmin");
            }
            return  View(ace);
        }

        //**********************edit user******************************
        public  ActionResult  edituser(int  id)
        {
            User  get = dc.Users.Where(ac => ac.user_id == id).First();
            return  View(get);
        }

         [HttpPost]
        public  ActionResult  edituser(int  id, User  us)
        {
            if  (ModelState.IsValid)
            {
                User  get = dc.Users.Where(ac => ac.user_id == id).First();

                get.user_id = us.user_id;
                get.user_name = us.user_name;
                get.password = us.password;
                get.first_name = us.first_name;
                get.last_name = us.last_name;
                get.address = us.address;
                get.phone_number = us.phone_number;
                get.email = us.email;
                get.gender = us.gender;
                get.DOB = us.DOB;
                get.rights = us.rights;
                dc.SubmitChanges();
                RedirectToAction("User", "templateadmin");
            }
            return  View(us);
        }

        //*********************edit ticket*******************************

 public  ActionResult  editticket(string  id)
        {
            Ticket  get = dc.Tickets.Where(ac => ac.ticket_id == id).First();
            return  View(get);
        }

         [HttpPost]
 public ActionResult editticket(string id, Ticket t)
        {
            if  (ModelState.IsValid)
            {
                Ticket  get = dc.Tickets.Where(ac => ac.ticket_id == id).First();

                get.ticket_id = t.ticket_id;
                get.bill_id = t.bill_id;
                get.flight_id = t.flight_id;
                get.ticket_date = t.ticket_date;
                get.type_id = t.type_id;
                get.child_num = t.child_num;
                get.class1 = t.class1;
                get.ticket_price = t.ticket_price;
                get.status = t.status;
                get.Payment_id = t.Payment_id;
                dc.SubmitChanges();
                RedirectToAction("Ticket", "templateadmin");
            }
            return  View(t);
        }
        //**************************edit Bill**************************************
       public  ActionResult  editbill(string  id)
        {
            Bill  get = dc.Bills.Where(ac => ac.bill_id == id).First();
            return  View(get);
        }

         [HttpPost]
       public ActionResult editbill(string id, Bill b)
        {
            if  (ModelState.IsValid)
            {
                Bill  get = dc.Bills.Where(ac => ac.bill_id == id).First();
                get.bill_id = b.bill_id;
                get.user_id = b.user_id;
                get.date = b.date;
                dc.SubmitChanges();
                RedirectToAction("Bill", "templateadmin");
            }
            return  View(b);
        }

        //*****************************edit destinaton***************************************
       public  ActionResult  editdestination(int  id)
        {
            Destination  get = dc.Destinations.Where(ac => ac.destination_id == id).First();
            return  View(get);
        }

         [HttpPost]
       public ActionResult editdestination(int id, Destination d)
        {
            if  (ModelState.IsValid)
            {
                Destination  get = dc.Destinations.Where(ac => ac.destination_id == id).First();
                get.destination_id = d.destination_id;
                get.place_name = d.place_name;
                get.place_parentid = d.place_parentid;
                dc.SubmitChanges();
                RedirectToAction("Destination", "templateadmin");
            }
            return  View(d);
        }
        //**************************************************************************//
         public ActionResult editorgin(int id)
         {
             Orgin get = dc.Orgins.Where(ac => ac.orgin_id == id).First();
             return View(get);
         }

         [HttpPost]
         public ActionResult editorgin(int id, Orgin o)
         {
             if (ModelState.IsValid)
             {
                 Orgin get = dc.Orgins.Where(ac => ac.orgin_id == id).First();
                 get.orgin_id =o.orgin_id;
                 get.place_name =o.place_name;
                 get.place_parentid = o.place_parentid;
                 dc.SubmitChanges();
                 RedirectToAction("Orgin", "templateadmin");
             }
             return View(0);
         }
         //**************************************************************************//
         public ActionResult editformpayment(int id)
         {
             formpayment get = dc.formpayments.Where(ac => ac.payment_id == id).First();
             return View(get);
         }

         [HttpPost]
         public ActionResult editformpayment(int id, formpayment fp)
         {
             if (ModelState.IsValid)
             {
                 formpayment get = dc.formpayments.Where(ac => ac.payment_id == id).First();
                 get.payment_id = fp.payment_id;
                 get.payment_name = fp.payment_name;
                 dc.SubmitChanges();
                 RedirectToAction("Formpayment", "templateadmin");
             }
             return View(fp);
         }
         //**************************************************************************//
         public ActionResult edittypeticket(int id)
         {
             TypeTicket get = dc.TypeTickets.Where(ac => ac.type_id == id).First();
             return View(get);
         }

         [HttpPost]
         public ActionResult edittypeticket(int id, TypeTicket tt)
         {
             if (ModelState.IsValid)
             {
                 TypeTicket get = dc.TypeTickets.Where(ac => ac.type_id == id).First();
                 get.type_id = tt.type_id;
                 get.flight_id = tt.flight_id;
                 get.type_name = tt.type_name;
                 get.type_price = tt.type_price;
                 dc.SubmitChanges();
                 RedirectToAction("TypeTicket", "templateadmin");
             }
             return View(tt);
         }
    }
}
